<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
    <title>Coverage Report :: PlayerCollisions</title>
    <style type="text/css">
        @import "../../.css/coverage.css";
    </style>
</head>

<body>
<div class="header"></div>

<div class="content">
    <div class="breadCrumbs">
        [ <a href="../../index.html">all classes</a> ]
        [ <a href="../index.html">nl.tudelft.jpacman.level</a> ]
    </div>

    <h1>Coverage Summary for Class: PlayerCollisions (nl.tudelft.jpacman.level)</h1>

    <table class="coverageStats">
        <tr>
            <th class="name">Class</th>
            <th class="coverageStat
">
                Class, %
            </th>
            <th class="coverageStat
">
                Method, %
            </th>
            <th class="coverageStat
">
                Line, %
            </th>
        </tr>
        <tr>
            <td class="name">PlayerCollisions</td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 1)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 7)
  </span>
            </td>
            <td class="coverageStat">
  <span class="percent">
    0%
  </span>
                <span class="absValue">
    (0/ 21)
  </span>
            </td>
        </tr>

    </table>

    <br/>
    <br/>


    <div class="sourceCode"><i>1</i>&nbsp;package nl.tudelft.jpacman.level;
        <i>2</i>&nbsp;
        <i>3</i>&nbsp;import nl.tudelft.jpacman.board.Unit;
        <i>4</i>&nbsp;import nl.tudelft.jpacman.npc.Ghost;
        <i>5</i>&nbsp;import nl.tudelft.jpacman.points.PointCalculator;
        <i>6</i>&nbsp;
        <i>7</i>&nbsp;/**
        <i>8</i>&nbsp; * A simple implementation of a collision map for the JPacman player.
        <i>9</i>&nbsp; * &lt;p&gt;
        <i>10</i>&nbsp; * It uses a number of instanceof checks to implement the multiple dispatch for the
        <i>11</i>&nbsp; * collisionmap. For more realistic collision maps, this approach will not scale,
        <i>12</i>&nbsp; * and the recommended approach is to use a {@link CollisionInteractionMap}.
        <i>13</i>&nbsp; *
        <i>14</i>&nbsp; * @author Arie van Deursen, 2014
        <i>15</i>&nbsp; *
        <i>16</i>&nbsp; */
        <i>17</i>&nbsp;
        <i>18</i>&nbsp;public class PlayerCollisions implements CollisionMap {
        <i>19</i>&nbsp;
        <i>20</i>&nbsp; private PointCalculator pointCalculator;
        <i>21</i>&nbsp;
        <i>22</i>&nbsp; /**
        <i>23</i>&nbsp; * Create a simple player-based collision map, informing the
        <i>24</i>&nbsp; * point calculator about points to be added.
        <i>25</i>&nbsp; *
        <i>26</i>&nbsp; * @param pointCalculator
        <i>27</i>&nbsp; * Strategy for calculating points.
        <i>28</i>&nbsp; */
        <b class="nc"><i>29</i>&nbsp; public PlayerCollisions(PointCalculator pointCalculator) {</b>
        <b class="nc"><i>30</i>&nbsp; this.pointCalculator = pointCalculator;</b>
        <i>31</i>&nbsp; }
        <i>32</i>&nbsp;
        <i>33</i>&nbsp; @Override
        <i>34</i>&nbsp; public void collide(Unit mover, Unit collidedOn) {
        <b class="nc"><i>35</i>&nbsp; if (mover instanceof Player) {</b>
        <b class="nc"><i>36</i>&nbsp; playerColliding((Player) mover, collidedOn);</b>
        <i>37</i>&nbsp; }
        <b class="nc"><i>38</i>&nbsp; else if (mover instanceof Ghost) {</b>
        <b class="nc"><i>39</i>&nbsp; ghostColliding((Ghost) mover, collidedOn);</b>
        <i>40</i>&nbsp; }
        <b class="nc"><i>41</i>&nbsp; else if (mover instanceof Pellet) {</b>
        <b class="nc"><i>42</i>&nbsp; pelletColliding((Pellet) mover, collidedOn);</b>
        <i>43</i>&nbsp; }
        <i>44</i>&nbsp; }
        <i>45</i>&nbsp;
        <i>46</i>&nbsp; private void playerColliding(Player player, Unit collidedOn) {
        <b class="nc"><i>47</i>&nbsp; if (collidedOn instanceof Ghost) {</b>
        <b class="nc"><i>48</i>&nbsp; playerVersusGhost(player, (Ghost) collidedOn);</b>
        <i>49</i>&nbsp; }
        <b class="nc"><i>50</i>&nbsp; if (collidedOn instanceof Pellet) {</b>
        <b class="nc"><i>51</i>&nbsp; playerVersusPellet(player, (Pellet) collidedOn);</b>
        <i>52</i>&nbsp; }
        <i>53</i>&nbsp; }
        <i>54</i>&nbsp;
        <i>55</i>&nbsp; private void ghostColliding(Ghost ghost, Unit collidedOn) {
        <b class="nc"><i>56</i>&nbsp; if (collidedOn instanceof Player) {</b>
        <b class="nc"><i>57</i>&nbsp; playerVersusGhost((Player) collidedOn, ghost);</b>
        <i>58</i>&nbsp; }
        <i>59</i>&nbsp; }
        <i>60</i>&nbsp;
        <i>61</i>&nbsp; private void pelletColliding(Pellet pellet, Unit collidedOn) {
        <b class="nc"><i>62</i>&nbsp; if (collidedOn instanceof Player) {</b>
        <b class="nc"><i>63</i>&nbsp; playerVersusPellet((Player) collidedOn, pellet);</b>
        <i>64</i>&nbsp; }
        <i>65</i>&nbsp; }
        <i>66</i>&nbsp;
        <i>67</i>&nbsp;
        <i>68</i>&nbsp; /**
        <i>69</i>&nbsp; * Actual case of player bumping into ghost or vice versa.
        <i>70</i>&nbsp; *
        <i>71</i>&nbsp; * @param player
        <i>72</i>&nbsp; * The player involved in the collision.
        <i>73</i>&nbsp; * @param ghost
        <i>74</i>&nbsp; * The ghost involved in the collision.
        <i>75</i>&nbsp; */
        <i>76</i>&nbsp; public void playerVersusGhost(Player player, Ghost ghost) {
        <b class="nc"><i>77</i>&nbsp; pointCalculator.collidedWithAGhost(player, ghost);</b>
        <b class="nc"><i>78</i>&nbsp; player.setAlive(false);</b>
        <b class="nc"><i>79</i>&nbsp; player.setKiller(ghost);</b>
        <i>80</i>&nbsp; }
        <i>81</i>&nbsp;
        <i>82</i>&nbsp; /**
        <i>83</i>&nbsp; * Actual case of player consuming a pellet.
        <i>84</i>&nbsp; *
        <i>85</i>&nbsp; * @param player
        <i>86</i>&nbsp; * The player involved in the collision.
        <i>87</i>&nbsp; * @param pellet
        <i>88</i>&nbsp; * The pellet involved in the collision.
        <i>89</i>&nbsp; */
        <i>90</i>&nbsp; public void playerVersusPellet(Player player, Pellet pellet) {
        <b class="nc"><i>91</i>&nbsp; pointCalculator.consumedAPellet(player, pellet);</b>
        <b class="nc"><i>92</i>&nbsp; pellet.leaveSquare();</b>
        <i>93</i>&nbsp; }
        <i>94</i>&nbsp;
        <i>95</i>&nbsp;}
    </div>
</div>

<div class="footer">

    <div style="float:right;">generated on 2023-04-25 16:45</div>
</div>
</body>
</html>
